<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
	<th:block th:include="include :: header('栏目')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			 <div class="col-sm-12 select-info">
				<form id="dept-form">
					<div class="select-list gd">
						<ul>
							<li>
								栏目名称：<input type="text" name="name"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
                
            <div class="btn-group hidden-xs" id="toolbar" role="group">
		        <a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add(1)" shiro:hasPermission="article:channel:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
	        </div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-tree-table"></table>
			</div>
	    </div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
        var addFlag = [[${@permission.hasPermi('system:content:column:add')}]];
		var editFlag = [[${@permission.hasPermi('system:content:column:edit')}]];
		var removeFlag = [[${@permission.hasPermi('system:content:column:remove)}]];
		var disable = [[${@dict.getType('sys_normal_disable')}]];
		var datas = [[${@dict.getType('system_content_column_type')}]];
		var yesNo = [[${@dict.getType('system_content_yes_no')}]];
        var prefix = ctx + "system/content/column";
        // window.onload = function() {
		// 	loading();
		// };
		$(function() {
			loading();
		});
		function loading() {
		    var options = {
				code: "id",
				parentCode: "pid",
				uniqueId: "id",
		        url: prefix + "/list",
		        createUrl: prefix + "/add/{id}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove/{id}",
		        modalName: "栏目",
		        columns: [
					{
						field: 'selectItem',
						radio: true
					},
					{
					field : 'name', 
					title : '栏目名称' 
				},
				{
					field : 'type', 
					title : '栏目的类型',
					align: "left",
		            formatter: function(value, row, index) {
						return $.table.selectDictLabel(datas, value);
		            }
				},
				{
					field : 'recommend', 
					title : '是否推荐' ,
					align: "left",
		            formatter: function(value, row, index) {
						return $.table.selectDictLabel(yesNo, value);
		            }
				},
				{
					field : 'isIndex', 
					title : '是否主页栏目' ,
					align: "left",
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(yesNo, value);
		            }
				},
				{
					field : 'isTopNav', 
					title : '是否导航栏目' ,
					align: "left",
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(yesNo, value);
		            }
				},
				{
					field : 'status', 
					title : '栏目状态' ,
					align: "left",
					formatter: function(value, row, index) {
		                return $.table.selectDictLabel(disable, value);
		            }
				},
		        {
		            title: '操作',
		            align: 'left',
		            formatter: function(value, row, index) {
		                if (row.pid != 0) {
		                    var actions = [];
		                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit">编辑</i></a> ');
		                    actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="#" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus">新增</i></a> ');
		                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove">删除</i></a>');
		                    return actions.join('');
		                } else {
		                    return "";
		                }
		            }
		        }]
		    };
		    $.treeTable.init(options);
		}
		
		function remove(id) {
			$.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗？", function() {
				$.ajax({
					type : 'post',
					url: prefix + "/remove/" + id,
					success : function(result) {
						if (result.code == web_status.SUCCESS) {
		                	$.modal.alertSuccess(result.msg);
		                	$.treeTable.refresh();
		                } else {
		                	$.modal.alertError(result.msg);
		                }
					}
				});
			});
		}
		
    </script>
</body>
</html>